package org.bookshare.document.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * Components of a DocumentSet.
 * @author Reuben Firmin
 */
public enum DocumentComponent {
	/** SMIL content. */
	SMIL(".*\\.[sS][mM][iI][lL]", "DAISY Navigation SMIL File", ComponentAttribute.TEXT, ComponentAttribute.XML),
    /** NCX content. */
	NCX(".*\\.[nN][cC][xX]", "DAISY Navigation NCX", ComponentAttribute.TEXT, ComponentAttribute.XML),
    /** XML content. */
    XML(".*\\.[xX][mM][lL]", "NIMAS Content XML File", ComponentAttribute.TEXT, ComponentAttribute.XML),
    /** XML content. */
    HTML(".*\\.[hH][tT][mM][lL]?", "HTML File", ComponentAttribute.XML, ComponentAttribute.TEXT),
	/** RTF content. */
    RTF(".*\\.[rR][tT][fF]", "RTF File", ComponentAttribute.TEXT),
    /** Properties. */
    PROPERTIES("(.*\\.[pP][rR][oO][pP][eE][rR][tT][iI][eE][sS])", "Properties File", ComponentAttribute.TEXT),
    /** OPF, package metadata, content. */
    OPF(".*\\.[oO][pP][fF]", "OPF Manifest File", ComponentAttribute.TEXT, ComponentAttribute.XML),
    /** PDF title / front page. */
    PDF(".*\\.[pP][dD][fF]", "PDF File"),
    /** Images. */
    IMAGE("(.*\\.[pP][nN][gG])|(.*\\.[gG][iI][fF])|(.*\\.[jJ][pP][gG])", "Image File");


    /**
     * Describes qualities of a DocumentType.
     */
    public static enum ComponentAttribute {
    	/** Text based file. */
    	TEXT,
    	/** XML based file. */
    	XML;
    }

	private String fileRegexp;
    private String description;
    private List<ComponentAttribute> attributes;

    /**
     * Construct.
     * @param fileRegexp The regexp that this type may have
     * @param description The human readable description of this type
     * @param attributes The attributes of this type
     */
    DocumentComponent(final String fileRegexp, final String description, final ComponentAttribute... attributes) {
        this.fileRegexp = fileRegexp;
        this.description = description;
        if (attributes != null) {
        	this.attributes = new ArrayList<ComponentAttribute>();
        	for (ComponentAttribute attribute : attributes) {
        		this.attributes.add(attribute);
        	}
        }
    }

    /**
     * The regexp that can be used to find this type.
     * @return not null
     */
    public final String getFileRegexp() {
        return fileRegexp;
    }

    /**
     * The human readable description of this type.
     * @return not null
     */
    public final String getDescription() {
        return description;
    }

    /**
     * Flag describing attributes of the type.
     * @return never null
     */
    public final List<ComponentAttribute> getAttributes() {
    	return attributes;
    }
}
